//
//  ViewController.m
//  Masonry
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 changshuhua. All rights reserved.
//

#import "ViewController.h"
#import <Masonry.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
#if 0
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
//    300*300 居中
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(300, 300));
        
    }];
//    1.make方法只负责增加新的约束,但是不能同时出现两条针对同一对象的约束,否则会报错
//    2.update方法针对上面的情况,会更新约束以确保不会出现两条相同的约束
//    3.remake方法会清除之前所有约束

    UIView *view1 = [UIView new];
    view1.backgroundColor = [UIColor yellowColor];
//    一定要先将view铁道上级视图上在创建约束
    [self.view addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view).with.offset(15);
//        make.left.equalTo(self.view).with.offset(15);
//        make.bottom.equalTo(self.view).with.offset(- 15);
//        make.right.equalTo(self.view).with.offset(- 15);
//        make.left.top.right.bottom.equalTo(self.view).insets(UIEdgeInsetsMake(15, 15, 15, 15));
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(15, 15, 15, 15));
    }];
#endif
//    两个高度为1510的view 居中并且等宽等间距宽度自动计算
    UIView *firstView = [[UIView alloc] init];
    firstView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:firstView];
    UIView *secondView = [[UIView alloc] init];
    secondView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:secondView];
    [firstView mas_makeConstraints:^(MASConstraintMaker *make) {
        // 设置对称轴
        make.centerY.equalTo(self.view.mas_centerY);
        make.left.equalTo(self.view).with.offset(15);
//        因为firstview的右侧是相对于secondview的左侧所以加上mas_left
        make.right.equalTo(secondView.mas_left).with.offset(-15);
        make.height.mas_equalTo(150);
        make.width.equalTo(secondView);
    }];
    [secondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view.mas_centerY);
        make.left.equalTo(firstView.mas_right).with.offset(15);
        make.right.equalTo(self.view).with.offset(-15);
        make.height.equalTo(firstView);
        make.width.equalTo(firstView);
    }];
    
    
    
    
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
